<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@taglib uri="http://www.springframework.org/tags" prefix="spring"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<link rel="stylesheet" type="text/css"
	href="<c:url value="/static/jquery-easyui/themes/default/easyui.css"/>">
<link rel="stylesheet" type="text/css"
	href="<c:url value="/static/jquery-easyui/themes/icon.css"/>">
<link rel="Stylesheet" type="text/css"
	href="<c:url value="/static/css/jquery.ui.css"/>" />
<script type="text/javascript"
	src="<c:url value="/static/jquery-easyui/jquery-1.6.min.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/static/jquery-easyui/jquery.easyui.min.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/static/jquery-easyui/plugins/jquery.panel.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/static/jquery-easyui/plugins/jquery.datagrid.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/static/jquery-easyui/plugins/jquery.messager.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/static/jquery-easyui/ext-for-framework.js.jsp"/>"></script>
<script type="text/javascript"
	src="<c:url value="/static/jquery-easyui/locale/easyui-lang-zh_CN.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/static/js/common.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/static/js/Loading.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/static/js/showMsg.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/static/listBox/jquery.clever.listbox.js"/>"></script>

<script>
	var dataLeft;

	function initList(listDisplayEId) {
		$('#' + listDisplayEId)
				.datagrid(
						{
							url : "<c:url value="/supplier/findSupDistribute.do"/>"
									+ "?disDate="
									+ $('#orderDate').datebox("getValue"),
							nowrap : false,
							striped : true,
							collapsible : true,
							remoteSort : true,
							notSelectByRow : false,
							toolbar : [
									{
										id : listDisplayEId + '_btn_add',
										text : '新增',
										iconCls : 'icon-add',
										handler : function() {
											if( $('#orderDate').datebox("getValue")==""){
												alert("请填写日期");
												return false;
											}
											var new_win = window.open( "<c:url value='/jsp/openIndexSun.jsp?url=/supplier/preSaveDistribute.do'/>"+"?disDate=" + $('#orderDate').datebox("getValue"),"sun","width=1200px,height=600px,status=no,scrollbars=yes");
											new_win.focus();
											$('#' + listDisplayEId).datagrid('reload');
										}
									},
									'-',
									{
		                                id : listDisplayEId + '_btn_del',
		                                text : '删除',
		                                iconCls : 'icon-cancel',
		                                handler : function() {

		                                    var row = $('#' + listDisplayEId).datagrid('getSelections');
		                                    if (row.length == 0) {
		                                        $.messager.alert('提示', '请选择一条记录操作！', 'info');
		                                        return;
		                                    } else {
		                                        var str = "disId=" + row[0]['disId'] + "&disDate="+ row[0]['disDate'];
		                                        $.messager.confirm('提示', '是否删除该条记录？', function(r) {
		                                            if (r) {
		                                                $.ajax({
		                                                    type : 'post',
		                                                    url : "<c:url value='/supplier/deleteSupplierDistribute.do'/>",
		                                                    data : str,
		                                                    dataType : "json",//设置查询参数及提交路径
		                                                    success : function(data) {
		                                                        if (data.success) {
		                                                            $.messager.alert("提示", "删除成功！", 'info');
		                                                            $('#' + listDisplayEId).datagrid('reload');
		                                                        } else {
		                                                            $.messager.alert("提示", data.msg, 'warning');
		                                                        }
		                                                    },
		                                                    error : function() {
		                                                        $.messager.alert("错误", "系统错误，请联系管理员！", 'error');
		                                                    }
		                                                });
		                                            }
		                                            $('#' + listDisplayEId).datagrid('reload');
		                                        });
		                                    }

		                                }
		                            } ],
							onLoadError : function() {
								$.messager.alert('错误', '获取数据失败，请与管理员联系！',
										'error');
							}
						});
	};

	function excel() {
		$('#AddFoodForm').form('submit', {
			url : '<c:url value='/supplierDistribute/importSupDistribute.do'/>',
			onSubmit : function()//提交按钮相应函数
			{
				var Allwidth = '100%';
				var Allheight = '100%';
				Loading.Show({width:Allwidth,height:Allheight});
                setTimeout(function(){
                    Loading.Hide();
                },3000)
				return $('#AddFoodForm').form('validate');
			},
			success : function(data) {
				data = eval( "("+data+")" );
                if(data.success){
                    $.messager.alert("提示", "生成成功！", 'info');
                }else{
                    var message = "";
                    if(data.msg == "locked"){
                        message = "正在生成文件！";
                    }else {
                        message =data.msg;
                    }
                    $.messager.alert("提示", message, 'warning');
                }
			},
			error : function() {
				$.messager.alert("错误", "系统错误，请联系管理员！", 'error');
				return;
			}
		});
	}
	
	function exceldown(){
        $('#AddFoodForm').form('submit',
                {
                    url:'<c:url value='/supplierDistribute/importSupDistributeDown.do'/>', //查询提交路径
                    onSubmit:function()//提交按钮相应函数
                    {
                        var Allwidth = '100%';
                        var Allheight = '100%';
                        Loading.Show({width:Allwidth,height:Allheight});
                        setTimeout(function(){
                            Loading.Hide();
                        },3000)
                        //校验
                        if($('#orderDate').datebox('getValue') ==''){
                            $.messager.alert('提示','订单日期没有填写！','info');
                            closeShow();
                        }
                        return $('#AddFoodForm').form('validate');
                    },
                    success:function(data){
                        if(typeof(data)=='string'){
                            data =JSON.parse(data);
                        }
                        if(data.success){
                            $.messager.alert("提示", "生成成功！", 'info');
                        }else{
                            var message = "";
                            if(data.msg == "locked"){
                                message = "正在生成文件！";
                            }else if(data.msg == "msg001"){
                                message = "没有生成，请先生成。";
                            }else if(data.msg == "msg0001"){
                                message = "价格没有导入！请先导入报表价格！";
                            }
                            $.messager.alert("提示", message, 'warning');
                        } 
                    },
                    error:function(){
                        $.messager.alert("错误", "系统错误，请联系管理员！", 'error');
                        return;
                    }
                });
        
        
    }
	$(document).ready(function() {
		initList("listDisplay");
		initHtmlProperties();
	});
	function initHtmlProperties() {
		$('#orderDate').datebox({
			onSelect : function(date) {
				initList("listDisplay");
			}
		});
	}

	function searchInfo() {
		if ($('#ordDate').combobox('getValue') == '') {
			alert("订单日不能为空");
		} else {
			$('#listDisplay').datagrid('load', {
				initFlag : 1,
				ordDate : $('#ordDate').datebox('getValue')
			});
		}
	}
</script>
</head>
<body>
	<table width="98%">
		<tr>
			<td>
				<form id="AddFoodForm" name="AddFoodForm" method="post">
					<div
						style="height: auto; width: 1180px; background: #fafafa; padding: 5px;"
						class="easyui-panel" title="送货报表导出" iconCls="icon-add"
						collapsible="true" minimizable="false" maximizable="false"
						closable="false">
						<table cellpadding="5">
							<tr>
								<td>日期</td>
								<td><input class="easyui-datebox" name="orderDate"
									id="orderDate" editable="false" data-options="required:true" />
								</td>
								<td><a href="#" class="easyui-linkbutton"
									onclick="excel();">生成</a></td>
							    <td>
                                    <a href="#" class="easyui-linkbutton" onclick="exceldown();">下载</a>
                                </td>

							</tr>
							<input class="easyui-validatebox" type="hidden" name="supId" value="0"  />
						</table>
					</div>
				</form>
			</td>
		</tr>

		<!-- <tr>
			<td>
				<form id="SeachForm" name="SeachForm" method="post"
					enctype="multipart/form-data">
					<div
						style="height: auto; width: 1180px; background: #fafafa; padding: 5px;"
						class="easyui-panel" title="查询模块属性" iconCls="icon-add"
						collapsible="true" minimizable="false" maximizable="false"
						closable="false">
						<table cellpadding="5">
							<tr>
								<td>订单日期</td>
								<td><input class="easyui-datebox" editable="false"
									id="ordDate" name="ordDate" required="true"></input></td>
								<td><a href="#" class="easyui-linkbutton"
									data-options="iconCls:'icon-search'" style="width: 60px"
									onclick="searchInfo()">查询</a></td>
							</tr>
						</table>
					</div>
				</form>

			</td>
		</tr> -->
		<tr>
			<td>
				<table id="listDisplay" title="批次列表" singleSelect=true
					iconCls="icon-list" idField="id"
					style="width: 800px; width: 1180px;" loadMsg="请稍候......"
					pagination="true" pageSize="10"
					pageList="[10,20,30,40,50,100,150,200]" sortName="disId"
					rownumbers="true" sortOrder="asc">
					<thead>
						<tr>
							<th field="materRole" width="25" align="center" checkbox="true"></th>
							<th field="disId" width="80" align="center">批次单号</th>
							<th field="supId" width="80" align="center">供货商id</th>
							<th field="supName" width="80" align="center">供货商名</th>
							<th field="custNameAll" width="200" sortable="true" editor="text">客户名称</th>
							<th field="disDate" width="80" sortable="true" editor="text">日期</th>
						</tr>
					</thead>
				</table>

		</td>
		</tr>
	</table>

</body>
</html>